<template>
    <page-container>
        <cu-custom :isBack="true" :backSolt='backSolt' bgColor="bg-white" slot="header">
            <!-- #ifdef MP-WEIXIN -->
            <block slot="backbox">
                <view class="flex-box">
                    <view class="goBack-icon" @click="BackPage">
                        <image :src="staticImgUrl+'chat/gobackIcon.png'" mode=""></image>
                    </view>
                    <view class="toStoreim-btn" @click="toShop()" v-if="site_id!=null">
                        进店
                    </view>
                </view>
            </block>
            <!-- #endif -->
            <block slot="content">
                <view class="text-center text-black ">{{site_name}}</view>
            </block>
            <!-- #ifdef H5 -->
            <block slot="right">
                <view class="toStoreim-btn" style="margin-right: 24rpx;" @click="toShop()" v-if="site_id!=null">
                    进店
                </view>
            </block>
            <!-- #endif -->
        </cu-custom>

        <block slot="center">
            <chitchat :site_id="site_id" :sku_id="sku_id"></chitchat>
        </block>

    </page-container>
</template>
<script>
import chitchat from '../components/chitchat/chitchat.vue'
export default {
	data() {
		return {
			backSolt: false,
			pagesLen: 0, // 页面栈数量,
			site_name: '',
			site_id: null,
			sku_id: null,
			goodsDetail: null,
			shopObj: null
		}
	},
	onLoad() {
		let optios = this.$util.queryObj()
		this.site_name = this.$util.queryObj().site_name
		if (optios.sku_id != undefined) {
			this.sku_id = optios.sku_id
			this.getDetails(optios.sku_id)
		}
		if (optios.site_id != undefined) {
			this.getinfo(optios.site_id)
		}
	},

	methods: {
		BackPage() {
			// 判断页面栈是否只有一个
			if (this.pagesLen == 1) {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			} else {
				uni.navigateBack({
					delta: 1
				})
			}
		},
		getDetails(sku_id) {
			this.$request.goodsskuDetail({ sku_id }).then(res => {
				// console.log("getDetails", res)
				this.goodsDetail = res.data.goods_sku_detail
				this.shopObj = res.data.shop_info
				this.site_name = res.data.shop_info.site_name
				this.site_id = res.data.shop_info.site_id
			})
				.catch(() => { })
		},
		toShop() {
			// console.log('点击了')
			this.$util.redirectTo('/shopPages/shop/shop', {
				site_id: this.site_id
			})

		},
		getinfo(site_id) {
			// console.log("site_id",site_id)
			if (site_id == 0) {
				return false
			}

			this.$request.shopInfo({
				site_id
			}).then(res => {
				// console.log("getinfo",res)
				this.site_name = res.data.site_name
				this.site_id = res.data.site_id
			}).catch(() => { })

		}

	},
	components: {
		chitchat
	},
	mounted() {
		// #ifdef MP-WEIXIN
		this.backSolt = true
		// #endif
		this.pagesLen = getCurrentPages().length
	}
}
</script>
<style lang="scss">
image {
    width: 100%;
    height: 100%;
}

.text-fontStyle {
    font-size: 36rpx;
    font-family: PingFang SC;
    font-weight: bold;
    color: #222222;
}

.toStoreim-btn {
    width: 96rpx;
    height: 50rpx;
    background: linear-gradient(180deg, #ff7124, #ff364e);
    border-radius: 25rpx;
    font-size: 24rpx;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ffffff;
    line-height: 50rpx;
    text-align: center;
}

.flex-box {
    display: flex;
    align-items: center;
}

.goBack-icon {
    width: 19rpx;
    height: 36rpx;
    margin-right: 40rpx;
}
</style>
